package com.test.test.controller;

import com.test.test.Service.GoodService;
import com.test.test.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/goods/")
public class GoodController {
    @Autowired
    private GoodService goodService;

    @RequestMapping("doGoodsUI")
    public String findGoods(Model model){
        List<Goods> list=goodService.find();
        model.addAttribute("goods",list);
        System.out.println(111111);
        return "good";

    }
    @RequestMapping("doDeleteById")
    public String doDeleteById(Integer id){
      goodService.deleteBYId(id);
      return "redirect:doGoodsUI";
    }
    @RequestMapping("doFindGoods")
    @ResponseBody
    public List<Goods> doFindGoods(){
        List<Goods> list=goodService.find();
        return list;
    }
    @RequestMapping("/doSaveObject")
    public String doInsert(Goods goods){

        goodService.insertObject(goods);
        return "redirect:doGoodsUI";
    }
}
